package com.mm.organizational.service;

import com.mm.organizational.dao.OrgMapper;
import com.mm.utils.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * C by Administrator on 2018/9/18/018.
 */
@Service
public class OrgService {
    @Autowired
    OrgMapper mapper;
    public List getList(Map map){
        map.put("id","0");
        return mapper.getList(map);
    }

    public void save(Map map) {
        String id = (String)map.get("id");

        if(StringUtils.isEmpty(id)){
            mapper.insert(map);
        }else{
            mapper.update(map);
        }
    }

    public void delete(Map reqMap) {
        String ids = (String)reqMap.get("ids");
        String[] idsArray = ids.split(",");
        String sqlIds = "";
        for(String id : idsArray){
            if(!sqlIds.equals("")){
                sqlIds += ",";
            }
            sqlIds += "'"+id+"'";
        }
        reqMap.put("ids",sqlIds);
        mapper.delete(reqMap);
    }
}
